home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 126-150 / scopedisk138 / envvariables / env.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  2.2 KB  |  81 lines

  1. /************************************************************************
  2.  * env.c -- print all the environment                                  *
  3.  *                                                                     *
  4.  *             Copyright 1990 Peter Chubb                              *
  5.  *               All rights reserved                                   *
  6.  *                                                                     *
  7.  ************************************************************************/
  8.  
  9. static char RCSID[] = "$Id: env.c,v 1.1 90/05/26 12:46:48 peterc Exp $";
  10.  
  11. /*
  12.  *
  13.  * $Log:       env.c,v $
  14.  * Revision 1.1  90/05/26  12:46:48  peterc
  15.  * Initial revision
  16.  * 
  17.  *
  18.  */
  19.  
  20. # include <exec/types.h>
  21. # include <proto/dos.h>
  22. # include <proto/exec.h>
  23. # include <string.h>
  24.  
  25. # define ENVDIR "ENV:"
  26. # define BUFSIZ 512
  27.  
  28. void
  29. _main()
  30. {
  31.     BPTR lck;
  32.     BPTR Op;
  33.     BPTR Ep;
  34.     struct FileInfoBlock *FB = AllocMem(sizeof(struct FileInfoBlock), 0);
  35.     long Status = 0;
  36.     register char *p;
  37.     register char *q;
  38.     int                  len;
  39.     struct DosLibrary *DOSBase;
  40.     char *buf = AllocMem(BUFSIZ, 0);
  41.  
  42.     if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 0)))
  43.        return;
  44.  
  45.     Op  = Output();
  46.   
  47.     lck = Lock(ENVDIR, SHARED_LOCK);
  48.     if (lck)
  49.     {
  50.        Status = Examine(lck, FB);
  51.        if (Status)
  52.            while (ExNext(lck, FB))
  53.            {
  54.                if (FB->fib_EntryType >= 0)
  55.                    continue;
  56.                Write(Op, FB->fib_FileName, strlen(FB->fib_FileName));
  57.                Write(Op, "=", 1);
  58.                for (p = ENVDIR, q = buf; *p; *q++ = *p++)
  59.                        ;
  60.                for (p = FB->fib_FileName; *p; *q++ = *p++)
  61.                        ;
  62.                *q = '\0';
  63.  
  64.        if ((Ep = Open(buf, MODE_OLDFILE)) != (BPTR)0)
  65.                {
  66.                    if ((len = Read(Ep, buf, BUFSIZ)) > 0)
  67.                    {
  68.                        Write(Op, buf, len);
  69.                    }
  70.                    Close(Ep);
  71.                }
  72.                Write(Op, "\n", 1);
  73.            }
  74.        UnLock(lck);
  75.     }
  76.  
  77.     CloseLibrary((struct Library *)DOSBase);
  78.     FreeMem(buf, BUFSIZ);
  79.     FreeMem(FB, sizeof (*FB));
  80. }
  81.